package com.ruoyi.web.xxj.contoller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.web.xxj.domain.ShopCart;
import com.ruoyi.web.xxj.service.IShopCartService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "购物车管理")
@RestController
@RequestMapping("/xxj/shopCart")
public class ShopCartController extends BaseController {

    @Autowired
    private IShopCartService shopCartService;

    /**
     * 查询购物车列表
     */
    @ApiOperation("查询购物车列表")
    @GetMapping("/list")
    public TableDataInfo<ShopCart> list(ShopCart shopCart) {
        startPage();
        List<ShopCart> list = shopCartService.selectShopCartList(shopCart);
        return getDataTable(list);
    }

    /**************************************** 以下是小程序接口 **********************************************/

    /**
     * 小程序：查询购物车列表
     */
    @ApiOperation("[小程序]查询购物车列表")
    @GetMapping("/miniList")
    public TableDataInfo<ShopCart> miniList() {
        startPage();
        List<ShopCart> list = shopCartService.selectShopCartList(new ShopCart(SecurityUtils.getWeChatUserId()));
        return getDataTable(list);
    }
    
    /**
     * 新增购物车
     */
    @ApiOperation("[小程序]新增购物车信息")
    @PostMapping
    public AjaxResult add(@RequestBody ShopCart shopCart) {
        return toAjax(shopCartService.insertShopCart(shopCart));
    }

    /**
     * 修改购物车
     */
    @ApiOperation("[小程序]修改购物车信息")
    @PutMapping
    public AjaxResult edit(@RequestBody ShopCart shopCart) {
        return toAjax(shopCartService.updateShopCart(shopCart));
    }

    /**
     * 删除购物车
     */
    @ApiOperation("[小程序]删除购物车信息")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(shopCartService.deleteShopCartByIds(ids));
    }
}
